package net.cyndeline.fov.mrpas.defaultImpl

import net.cyndeline.fov.mrpas.Line

/**
 * Represents a basic line of coordinates on a map. Makes no
 * attempts to ensure position consistency between positions added,
 * other than removing duplicates.
 */
class DefaultLine extends Line {
  var positions = List[(Int, Int)]()
  var obstacles = Set[(Int, Int)]()
  var previousObstacles = 0
  
  def length: Int = positions.size
  
  def addPosition(position: (Int, Int)): Boolean = {
    if (positions contains position) {
      false
    } else {
      positions = positions :+ position
      true
    }
  }
  
  def tilePositions: List[(Int, Int)] = {
    positions
  }
  
  def addObstacle(position: (Int, Int)): Boolean = {
    if (positions contains position) {
      obstacles += position
      true
    } else {
      false
    }
  }
  
  def isObstacle(pos: (Int, Int)): Boolean = obstacles contains pos
  
  def obstaclesUpToThisLine_=(amount: Int) {
    previousObstacles = amount
  }
  
  def obstaclesUpToThisLine: Int = previousObstacles
  
  def obstaclesFoundToThisLine: Int = obstacles.size + previousObstacles
}